/*
 * @Author: whr2349
 * @Date: 2021-06-30 10:14:47
 * @LastEditors: whr2349
 * @LastEditTime: 2021-07-05 10:15:30
 * @Description: file content
 * @FilePath: \back\app\model\organization.js
 */

"use strict";
const moment = require('moment');

module.exports = app => {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;

    const OrganizationSchema = new Schema({
        name: {
            type: String,
            unique: true,
            trim: true
        },
        key: {
            type: String,
            unique: true,
            trim: true,
        },
        superiorKey: {
            type: String,
            trim: true,
        },
        sort: {
            type: Number,
            default: 1,
        },
        isUsing: {
            type: Boolean,
            default: true,
        },
        isDelete: {
            type: Boolean,
            default: false,
        },
        createdTime: { type: Number },
        updatedTime: { type: Number },
    },
        {
            versionKey: false,
            timestamps: {
                createdAt: 'createdTime',
                updatedAt: 'updatedTime',
                currentTime: () => Date.now()
            },
        });
    // OrganizationSchema.set('toObject', { getters: true}) // 这个也是必须的
    return mongoose.model('Organization', OrganizationSchema, "organization");
}